package General;

import javax.swing.*;

import Exception.*;

public class TreatError
{
	public static void showError(Exception error)
	{
		if(error instanceof OpenConnectionException) //If the error is an OpenConnectionException type
			JOptionPane.showMessageDialog(null, "Source : CallDB.openConnection()\nProblem : Opening connection request\nDetail : " + error, "Exception - Request syntax error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof LoadDriverException) //If the error is an LoadDriverException type
			JOptionPane.showMessageDialog(null, "Source : CallDB.CallDB()\nProblem : Error to load the driver in the constructor\nDetail : " + error, "Exception - Driver loading error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof CheckDataException) //If the error is a CheckDataException type
			JOptionPane.showMessageDialog(null, "Source : CallDB.checkData()\nProblem : Retrieving request\nDetail : " + error, "Exception - Request syntax error !", JOptionPane.ERROR_MESSAGE); //Show error message 
		else if(error instanceof CloseConnectionException)//If the error is a CloseConnectionException type
			JOptionPane.showMessageDialog(null, "Source : CallDB.closeConnection()\nProblem : Failure of disconnection from sockets\nDetail : " + error, "Failure during disconnection !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof InsertionDataException) //If the error is an InsertDataException type
			JOptionPane.showMessageDialog(null, "Source : CallDB.insertData()\nProblem : Insertion request\nDetail : " + error, "Exception - Request syntax error !", JOptionPane.ERROR_MESSAGE); //Show error message	
		else if(error instanceof NumberFormatException) //If the error is a NumberFormatException type
			JOptionPane.showMessageDialog(null, "Source : parseInt method\nProblem : Unable to parse correctly\nDetail : " + error.getMessage(), "Exception - Number format Error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof InterruptedException) //If the error is an InterruptedException type
			JOptionPane.showMessageDialog(null, "Source : ThreadBar.run()\nProblem : Error Timer\nDetail : " +error.getMessage(), "Exception - Timer Exception !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof EraseDataException) //If the error is an EraseDataException type
			JOptionPane.showMessageDialog(null, "Source : CallDB.eraseData()\nProblem : Suppression request\nDetail : " + error, "Exception - Request syntax error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof Layer8TableException) //If the error is an Layer8TableException type
			JOptionPane.showMessageDialog(null, "Source : No selected row\nProblem : Unable to suppress a non selected row\nDetail : " + error, "Exception - Layour Eight error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof FormatScrollPaneException) //If the error is an FormatScrollPaneException type
			JOptionPane.showMessageDialog(null, "Source : Wrong parameter for GraphicSetting.formatColumnHeader() method\nProblem : ScrollPane Width\nDetail : " + error, "Exception - Wrong parameter error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof ComboModelException) //If the error is an ComboModelException type
			JOptionPane.showMessageDialog(null, "Source : Wrong parameter for GeneralMethod.comboModel() method\nProblem : String field\nDetail : " + error, "Exception - Wrong parameter error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof Layer8DataException) //If the error is an Layer8DataException type
			JOptionPane.showMessageDialog(null, "Source : Invalid data in the field(s)\nProblem : Invalid Data\nDetail : " + error, "Exception - Wrong field error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof ModificationDBException) //If the error is a ModificationDBException type
			JOptionPane.showMessageDialog(null, "Source : Modifications are forbidden\nProblem : Invalid selection" + "\nDetail : " + error, "Exception - Forbidden operation", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof OperationImpossibleException) //If the error is an OperationImpossibleException type
			JOptionPane.showMessageDialog(null, "Source : Course link\nProblem : Impossible operation\nDetail : " + error, "Exception - Request operation error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else if(error instanceof ConflictException) //If the error is a ConflictException type
			JOptionPane.showMessageDialog(null, "Source : Conflict in Database\nProblem : The object already exists\nDetail : " + error, "Exception - Impossible operation error !", JOptionPane.ERROR_MESSAGE); //Show error message
		else
			JOptionPane.showMessageDialog(null, "Source : WindowTeacher.MyActionListener.buttonAdd()\nProblem : Add new student in arrayList without a good time\nDetail : " + error, "Exception - Request syntax error !", JOptionPane.ERROR_MESSAGE); //Show error message
	}
}